<?php
/**
 * Created by PhpStorm.
 * User: HS032
 * Date: 2020/8/22
 * Time: 13:21
 */

namespace ticket\modules\backend\controllers;

use ticket\libs\Tools;
use ticket\modules\backend\models\Points;
use ticket\modules\backend\models\PointsLog;

use Yii;


class PointController extends BasicController
{

    //1-首页 2-首页门票 3-门票升级访问 4-年卡升级访问 5-门票升级二维码 6-年卡升级购买
    public function actionPointsLog()
    {
        if (Yii::$app->request->isPost){
            $post = Yii::$app->request->post();
            $start = isset($post['start'])?$post['start']:'';
            $end = isset($post['end'])?$post['end']:'';
            $point = Points::find()->where("state = 1")->asArray()->all();

            foreach($point as $k=>$v){
                $point_id = $v['id'];
                if(!empty($start) && !empty($end)){
                    //总扫码人数
                    $all_num_count = PointsLog::find()->where("point_id = $point_id and type = 1 and create_time >'$start' and create_time >'$end'")->count();
                    //首页门票升级入口访问人数
                    $home_nums_count = PointsLog::find()->where("point_id = $point_id and type = 2 and create_time >'$start' and create_time >'$end'")->count();
                    //门票升级访问人数
                    $ticket_nums_count = PointsLog::find()->where("point_id = $point_id and type = 3 and create_time >'$start' and create_time >'$end'")->count();
                    //年卡升级访问人数
                    $year_card_nums_count = PointsLog::find()->where("point_id = $point_id and type = 4 and create_time >'$start' and create_time >'$end'")->count();
                    //门票升级二维码生成人数
                    $ticket_buy_nums_count = PointsLog::find()->where("point_id = $point_id and type = 5 and create_time >'$start' and create_time >'$end'")->count();
                    //年卡升级购买人数
                    $year_card_buy_nums_count = PointsLog::find()->where("point_id = $point_id and type = 6 and create_time >'$start' and create_time >'$end'")->count();
                }else{
                    //总扫码人数
                    $all_num_count = PointsLog::find()->where("point_id = $point_id and type = 1")->count();
                    //首页门票升级入口访问人数
                    $home_nums_count = PointsLog::find()->where("point_id = $point_id and type = 2")->count();
                    //门票升级访问人数
                    $ticket_nums_count = PointsLog::find()->where("point_id = $point_id and type = 3")->count();
                    //年卡升级访问人数
                    $year_card_nums_count = PointsLog::find()->where("point_id = $point_id and type = 4")->count();
                    //门票升级二维码生成人数
                    $ticket_buy_nums_count = PointsLog::find()->where("point_id = $point_id and type = 5")->count();
                    //年卡升级购买人数
                    $year_card_buy_nums_count = PointsLog::find()->where("point_id = $point_id and type = 6")->count();
                }
                $point[$k]['all_nums'] = $all_num_count;
                $point[$k]['home_nums'] = $home_nums_count;
                $point[$k]['ticket_nums'] = $ticket_nums_count;
                $point[$k]['year_card_nums'] = $year_card_nums_count;
                $point[$k]['ticket_buy_nums'] = $ticket_buy_nums_count;
                $point[$k]['year_card_buy_nums'] = $year_card_buy_nums_count;

            }
            return Tools::showRes(0,'success',[
                'list' => $point,
            ]);
        }
    }



}